package com.example.snackfood.dao;

import com.example.snackfood.entity.Users;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @program: snackFood
 * @description:
 * @author: lydms
 * @create: 2023-11-22 21:21
 **/

@Component
public class SnackFoodUsersDao {
    @Resource
    private MongoTemplate mongoTemplate;

    /**
     * 增加用户
     * @param user
     */
    public void save(Users user) {
        mongoTemplate.save(user);
    }

    /**
     * 查所有用户信息
     * @return
     */
    public List<Users> findAll() {
        return mongoTemplate.findAll(Users.class);
    }

    public Users get(Query query) {
        return mongoTemplate.findOne(query,Users.class);
    }
    /**
     * 改用户信息
     * @param
     */
    public void update(Query query, Update update) {
        mongoTemplate.updateMulti(query, update,Users.class);
    }

    public void delete(Query query) {
        mongoTemplate.remove(query, Users.class);
    }

    public Users selectUserByUserName(Query query) {
        return mongoTemplate.findOne(query,Users.class);
    }
}
